package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.BtyCrk;
import cn.stylefeng.guns.sys.modular.system.mapper.BtyCrkMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyCrkParam;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyCrkDto;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyCrkResult;
import cn.stylefeng.guns.sys.modular.system.service.BtyCrkService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;


/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author liuy
 * @since 2021-12-10
 */
@Service
public class BtyCrkServiceImpl extends ServiceImpl<BtyCrkMapper, BtyCrk> implements BtyCrkService {
    @Resource
    private BtyCrkService crkService;

    @Override
    public void add(BtyCrkParam param) {
        BtyCrk entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BtyCrkParam param) {
        this.removeById(getKey(param));
    }

    @Override
    public void update(BtyCrkParam param) {
        BtyCrk oldEntity = getOldEntity(param);
        BtyCrk newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BtyCrkResult findBySpec(BtyCrkParam param) {
        return null;
    }

    @Override
    public List<BtyCrkResult> findListBySpec(BtyCrkParam param) {
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(BtyCrkParam param) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean insertCrk(List<BtyCrkDto> sub) {
        return baseMapper.insertCrk(sub);
    }

    @Override
    public List<BtyCrk> sflbList() {
        return baseMapper.sflbList();
    }

    @Override
    public List<BtyCrkResult> gysList(BtyCrkParam param) {
        return baseMapper.gysList(param);
    }

    @Override
    public List<BtyCrkResult> tpfkList() {
        return baseMapper.tpfkList();
    }

    @Override
    public int updateByDm(BtyCrkParam param) {
        return baseMapper.updateByDm(param);
    }

    @Override
    public int updateErrMsgByDm(BtyCrkParam param) {
        return baseMapper.updateErrMsgByDm(param);
    }

    private Serializable getKey(BtyCrkParam param) {
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BtyCrk getOldEntity(BtyCrkParam param) {
        return this.getById(getKey(param));
    }

    private BtyCrk getEntity(BtyCrkParam param) {
        BtyCrk entity = new BtyCrk();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
